﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.Generic;
using System.Xml;
using System.Xml.Linq;
using System.Linq;

namespace RenRenClient
{
    public delegate void GetFriendCallback(List<RennFriend> ar);

    public class RennFriend
    {
        /// <summary>
        /// 好友的用户ID
        /// </summary>
        public string ID { get; protected set; }
        /// <summary>
        /// 好友的名字
        /// </summary>
        public string Name { get; protected set; }
        /// <summary>
        /// 好友的名字
        /// </summary>
        public string HeadUrl { get; protected set; }
        /// <summary>
        /// 好友的头像
        /// </summary>
        public string TinyUrl { get;  protected set; }

        public static List<RennFriend> Parse(XDocument data)
        {
            XName qualifiedName = XName.Get("friend", RennURL.XmlNS);
            var friends = from item in data.Descendants(qualifiedName)
                          select new RennFriend
                          {
                              ID = item.Element(XName.Get("id", RennURL.XmlNS)).Value,
                              Name = item.Element(XName.Get("name", RennURL.XmlNS)).Value,
                              HeadUrl = item.Element(XName.Get("headurl", RennURL.XmlNS)).Value,
                              TinyUrl = item.Element(XName.Get("tinyurl", RennURL.XmlNS)).Value
                          };
            return friends.ToList();
        }
    }
}
